package com.firebird.oms.domain.sm;

// Generated 2009-11-20 18:24:23 by Hibernate Tools 3.2.5.Beta

import static javax.persistence.GenerationType.IDENTITY;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;

/**
 * TismRole generated by hbm2java
 */
@Entity
@Table(name = "tism_role")
public class TismRole implements java.io.Serializable {

	private static final long serialVersionUID = 1L;
	private Integer roleId;
	private String roleName;
	private int isShare;
	private Integer companyId;
	private String roleDesc;
	private Integer roleType;
	private int state;
	private Set<TismFunction> functions = new HashSet<TismFunction>(0);

	public TismRole() {
	}

	public TismRole(int isShare, int state) {
		this.isShare = isShare;
		this.state = state;
	}

	public TismRole(String roleName, int isShare, Integer companyId,
			String roleDesc, Integer roleType, int state) {
		this.roleName = roleName;
		this.isShare = isShare;
		this.companyId = companyId;
		this.roleDesc = roleDesc;
		this.roleType = roleType;
		this.state = state;
	}

	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "role_id", unique = true, nullable = false)
	public Integer getRoleId() {
		return this.roleId;
	}

	public void setRoleId(Integer roleId) {
		this.roleId = roleId;
	}

	@Column(name = "role_name", length = 64)
	public String getRoleName() {
		return this.roleName;
	}

	public void setRoleName(String roleName) {
		this.roleName = roleName;
	}

	@Column(name = "is_share", nullable = false)
	public int getIsShare() {
		return this.isShare;
	}

	public void setIsShare(int isShare) {
		this.isShare = isShare;
	}

	@Column(name = "company_id")
	public Integer getCompanyId() {
		return this.companyId;
	}

	public void setCompanyId(Integer companyId) {
		this.companyId = companyId;
	}

	@Column(name = "role_desc", length = 160)
	public String getRoleDesc() {
		return this.roleDesc;
	}

	public void setRoleDesc(String roleDesc) {
		this.roleDesc = roleDesc;
	}

	@Column(name = "role_type")
	public Integer getRoleType() {
		return this.roleType;
	}

	public void setRoleType(Integer roleType) {
		this.roleType = roleType;
	}

	@Column(name = "state", nullable = false)
	public int getState() {
		return this.state;
	}

	public void setState(int state) {
		this.state = state;
	}

	@ManyToMany(cascade = CascadeType.PERSIST)
	@LazyCollection(LazyCollectionOption.TRUE)
	@JoinTable(name = "tism_role_function", joinColumns = { @JoinColumn(name = "role_id") }, inverseJoinColumns = @JoinColumn(name = "func_id"))
	public Set<TismFunction> getFunctions() {
		return functions;
	}

	public void setFunctions(Set<TismFunction> functions) {
		this.functions = functions;
	}

	public boolean equals(final Object other) {
		if (!(other instanceof TismRole))
			return false;
		TismRole castOther = (TismRole) other;
		return new EqualsBuilder().append(roleId, castOther.roleId).append(
				roleName, castOther.roleName)
				.append(isShare, castOther.isShare).append(companyId,
						castOther.companyId).append(roleDesc,
						castOther.roleDesc)
				.append(roleType, castOther.roleType).append(state,
						castOther.state).append(functions, castOther.functions)
				.isEquals();
	}

	public int hashCode() {
		return new HashCodeBuilder().append(roleId).append(roleName).append(
				isShare).append(companyId).append(roleDesc).append(roleType)
				.append(state).append(functions).toHashCode();
	}

	public String toString() {
		return new ToStringBuilder(this).append("roleId", roleId).append(
				"roleName", roleName).append("isShare", isShare).append(
				"companyId", companyId).append("roleDesc", roleDesc).append(
				"roleType", roleType).append("state", state).append(
				"functions", functions).toString();
	}

}
